package com.cmcc.shared.data

import com.cmcc.shared.model.*
import retrofit2.Response

class PlatformRequest {
    private val platformApiService: PlatformApiService = Network.getInstance().apiService

    /**
     * 用户登录，获取token
     */
    suspend fun userLogin(
        myLinkToken: String,
        deviceToken: String
    ): Response<AppResponse<NetToken>> {
        var tokenInfo =
            LinkedToken(myLinkToken, deviceToken)
        return platformApiService.userLogin(tokenInfo).await()
    }

    /**
     * 获取用户信息
     */
    suspend fun getCardInfo(token: String): Response<AppResponse<CardInfo>> {
        return platformApiService.getCardInfo(token).await()
    }

    /**
     * 查询正在进行的订单
     */
    suspend fun queryOrderInProgress(token: String, role: Int = 1): Response<AppResponse<OrderRecord>> {
        return platformApiService.queryOrderInProgress(token, role).await()
    }

    /**
     * 更改司机工作状态
     */
    suspend fun changeDriverStatus(
        token: String,
        status: Int,
        coordinates: Coordinates
    ): Response<AppResponse<Int>> {
        val currentCoordinates = DriverCoordinates(status, coordinates)
        return platformApiService.switchWrok(token, currentCoordinates).await()
    }

    /**
     * 司机轨迹批量上传
     */
    suspend fun uploadBatch(
        token: String,
        listDriverTrice: List<DriverTrice>
    ): Response<AppResponse<String>> {
        return platformApiService.uploadBatch(token, listDriverTrice).await()
    }

    companion object {
        @Volatile
        private var instance: PlatformRequest? = null

        fun getInstance(): PlatformRequest {
            return instance ?: synchronized(this) {
                instance ?: PlatformRequest().also { instance = it }
            }
        }
    }

}